package xiao.ze.demo.utils;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import xiao.ze.demo.service.impl.UserServiceImpl;

import javax.annotation.Resource;
import java.util.Random;

/**
 * @description: TODO
 * @author: Tokyo_God
 * @date: 2021/2/14 12:34
 * Role of:
 * @version: v1.0
 */
@Component
public class MyUtil {
    @Resource
    UserServiceImpl userService;
    //////////生成  与数据库不相等的用户编号  /////////////////

    private Long createRandom(int digit) {
        int j = 1;
        for (int i = 1; i < digit; i++) {
            j *= 10;
        }
        Random r = new Random();
        long nonce = r.nextInt(9 * j) + j;
        return nonce;
    }

    public Long createUserNo(int digit) {
        Long sjs = Long.valueOf(0);
        while (true) {
            sjs = createRandom(digit);
            if (userService.selUserNo(sjs.toString()) == null) {
                break;
            }
        }
        return sjs;
    }

//    public static void main(String[] args) {
//        Random r = new Random();
//        long ws=r.nextInt(90000)+10000;
//        System.out.println(ws);
//    }
}
